package com.feng.chat.controller;

import cn.hutool.extra.mail.MailUtil;
import com.feng.chat.dto.Result;
import com.feng.chat.service.CommonService;
import com.feng.chat.utils.GetUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/common")
public class CommonController {
    @Autowired
    private CommonService commonService;

    /**
     * 发送邮箱验证码
     *
     * @param request
     * @param map
     * @return
     */
    @PostMapping("/email-code")
    public Result emailCode(HttpServletRequest request, @RequestBody Map<String, String> map) {
        HttpSession session = request.getSession();
        Result result = commonService.emailCode(map.get("email"), session);
        return result;
    }

    /**
     * 发送手机验证码
     *
     * @param request
     * @param map
     * @return
     */
    @PostMapping("/sms-code")
    public Result smsCode(HttpServletRequest request, @RequestBody Map<String, String> map) {
        HttpSession session = request.getSession();
        Result result = commonService.smsCode(map.get("channel"), map.get("mobile"), session);
        return result;
    }
}
